package com.dfrz.controller;

import com.dfrz.common.ResultEnum;
import com.dfrz.entity.Result;
import com.dfrz.entity.VideoDetail;
import com.dfrz.service.VideoDetailService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 29877
 */
@RestController
public class VideoDetailController {
    @Resource
    private VideoDetailService detailService;

    //添加续集
    @PostMapping("/loadDetail")
    public Result uploadDetail(String detailTitle, Integer detailNum,
                               Integer checkStatus,Integer videoUid ,MultipartFile detailImg,
                               MultipartFile detailVideo,Integer needVip) throws Exception {

        Integer detailType = 1; //谁发的视频？管理/普通用户
        VideoDetail videoDetail = new VideoDetail(detailTitle, detailNum, checkStatus,detailType,videoUid,needVip);
        detailService.insertAll(videoDetail,detailImg,detailVideo);
        return Result.success(ResultEnum.SUCCESS);
    }

    //根据vid查询所有分集
    @GetMapping("selectdetialbyvid")
    public Result selectDetialByVid(Integer vid){
         List<VideoDetail> details = detailService.selectdetialbyvid(vid);
         return Result.success(details);
    }

    //根据名字模糊查询用户发布的视频
    @GetMapping("selectdetailbyname")
    public Result selectDetailByName(String word){
        List<VideoDetail> details=detailService.selectdetialbytitle(word);
        return Result.success(details);
    }

    //根据vid查询用户视频的相关信息
    @GetMapping("static/getdetailinfobyid")
    public Result getdetailinfobyid(Integer vid){
        VideoDetail detail = detailService.getdetailinfobyid(vid);
        return Result.success(detail);
    }

    //首页普通用户视频渲染
    @GetMapping("static/getIndexV")
    public Result getIndexVideo(){
        List<Object> indexVideos = detailService.getVideoByRandom();
        return Result.success(indexVideos);
    }

    //滚动实现视频刷新
    @GetMapping("static/getIndexM")
    public Result getIndexVideoM(){
        List<Object> indexVideos = detailService.getVideoByRandomM();
        return Result.success(indexVideos);
    }

    //用户删除自己发布的视频
    @DeleteMapping("/deletedetail/{videoId}")
    public Result deleteDetailByVideoId(@PathVariable("videoId") Integer videoId){
        detailService.deleteDetailByVideoId(videoId);
        return Result.success(ResultEnum.SUCCESS);
    }

    //用户搜索自己发布的视频
    @GetMapping("getMyVideo")
    public Result getMyVideo(Integer userId,String videoTitle ){
        List<Object> videos = detailService.getMyVideo(userId,videoTitle);
        return Result.success(videos);
    }

    //获取待审核视频信息和数量用于分页
    @GetMapping("static/getCheckVideo")
    public Result getCheckVideo(){
        return Result.success(detailService.getCheckVideo());
    }

    //更新视频审核状态
    @PutMapping("updataCheck/{videoId}")
    public Result updataCheck(@PathVariable("videoId") Integer videoId){
        detailService.updataCheck(videoId);
        return Result.success(ResultEnum.SUCCESS);
    }

    //分页器分页请求视频
    @GetMapping("getPaging")
    public Result getPaging(Integer page){
        List<Object> pages = detailService.getPageing(page);
        return Result.success(pages);
    }
    //待审核视频的搜索
    @GetMapping("/getSearchChick/{videoTitle}")
    public Result selectVideoByName(@PathVariable("videoTitle") String videoTitle){
        Map<String,Object> videos = detailService.selectvideoByName(videoTitle);
        return Result.success(videos);
    }
}
